package com.redhat.redwork.widget;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.UIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;

import com.opensymphony.xwork2.util.ValueStack;

@StrutsTag(name = "topicBridge", tldTagClass = "com.redhat.redwork.widget.TopicBridgeTag", description = "well.. the topic bridge")
public class TopicBridge extends UIBean {

	public static final String TEMPLATE = "topic-bridge";

	protected String publisher;
	protected String publisherTopic;
	protected String subscriber;
	protected String subscriberTopic;

	public TopicBridge(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack, request, response);
	}
	
	@Override
	protected void evaluateExtraParams() {
		super.evaluateExtraParams();
		
		addParameter("publisher", findString(publisher));
		addParameter("publisherTopic", findString(publisherTopic));
		addParameter("subscriber", findString(subscriber));
		addParameter("subscriberTopic", findString(subscriberTopic));
	}

	@Override
	protected String getDefaultTemplate() {
		return TEMPLATE;
	}
	
	@Override
	@StrutsTagSkipInheritance
	public void setTheme(String theme) {
		super.setTheme(theme);
	}
	
	@Override
	public String getTheme() {
		return "redwork";
	}

	@StrutsTagAttribute(description = "publisher id")
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	@StrutsTagAttribute(description = "the original topic")
	public void setPublisherTopic(String publisherTopic) {
		this.publisherTopic = publisherTopic;
	}

	@StrutsTagAttribute(description = "subscriber id")
	public void setSubscriber(String subscriber) {
		this.subscriber = subscriber;
	}

	@StrutsTagAttribute(description = "the converted topic")
	public void setSubscriberTopic(String subscriberTopic) {
		this.subscriberTopic = subscriberTopic;
	}
}
